//
//  UIBarButtonItem+ZDExtension.m
//  SSSAllRollAgency
//
//  Created by Darker on 2017/3/10.
//  Copyright © 2017年 Darker. All rights reserved.
//

#import "UIBarButtonItem+ZDExtension.h"

@implementation UIBarButtonItem (ZDExtension)


/**
 *  返回导航栏左部头像
 *
 *  @param image     头像图片
 *  @param highImage 高亮图片
 *  @param target    self
 *  @param action    方法回调
 *
 *  @return 返回头像
 */
+ (instancetype)itemWithImage:(UIImage *)image highImage:(UIImage *)highImage target:(id)target action:(SEL)action
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame     = CGRectMake(0, 0, 30, 30);
    button.layer.cornerRadius = 15.0;
    button.layer.masksToBounds = YES;
    [button setImage:image forState:UIControlStateNormal];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[self alloc]initWithCustomView:button];
}


/**
 *  返回标题
 *
 *  @param title 文字标题
 *  @param color 文字颜色
 *
 *  @return 返回导航栏中间标题
 */
+ (instancetype)itemWithTitle:(NSString *)title color:(UIColor *)color
{
    UILabel *label = [[UILabel alloc]init];
    label.font = [SSSFont systemFontOfSize:17];
    label.textColor = color;
    label.text = title;
    [label sizeToFit];
    
    return [[self alloc]initWithCustomView:label];
}

/**
 *  完成按钮
 *
 *  @param title  显示文字标题
 *  @param color  字体颜色
 *  @param target self
 *  @param action 方法回调
 *
 *  @return 返回按钮
 */
+ (instancetype)itemWithTitle:(NSString *)title color:(UIColor *)color target:(id)target action:(SEL)action
{
    UIButton *signOutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    signOutBtn.titleLabel.font = [SSSFont systemFontOfSize:15];
    [signOutBtn setTitleColor:color forState:UIControlStateNormal];
    [signOutBtn setTitle:title forState:UIControlStateNormal];
    [signOutBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [signOutBtn sizeToFit];
    signOutBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -10);
    return [[self alloc]initWithCustomView:signOutBtn];
}

/**
 *  取消按钮
 *
 *  @param title  显示文字标题
 *  @param color  字体颜色
 *  @param target self
 *  @param action 方法回调
 *
 *  @return 返回按钮
 */
+ (instancetype)itemLeftWithTitle:(NSString *)title color:(UIColor *)color target:(id)target action:(SEL)action
{
    UIButton *signOutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    signOutBtn.titleLabel.font = [SSSFont systemFontOfSize:17];
    [signOutBtn setTitleColor:color forState:UIControlStateNormal];
    [signOutBtn setTitle:title forState:UIControlStateNormal];
    [signOutBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [signOutBtn sizeToFit];
    signOutBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    return [[self alloc]initWithCustomView:signOutBtn];
}


/**
 *  返回箭头
 *
 *  @param image     图片
 *  @param highImage 高亮图片
 *  @param title     nil
 *  @param target    self
 *  @param action    方法回调
 *
 *  @return 返回箭头
 */
+ (instancetype)itemNavWithImage:(NSString *)image highImage:(NSString *)highImage title:(NSString *)title target:(id)target action:(SEL)action {
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backButton setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [backButton setTitle:title forState:UIControlStateNormal];
    [backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
    [backButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    backButton.titleLabel.font = [SSSFont systemFontOfSize:18];
    [backButton sizeToFit];
    return [[self alloc]initWithCustomView:backButton];
}

/**
 *  联系客服按钮设置
 *
 *  @param image     图片
 *  @param highImage 高亮图片
 *  @param title     联系客服
 *  @param target    self
 *  @param action    方法回调
 *
 *  @return 按钮
 */
+ (instancetype)itemNavLinkServiceWithImage:(NSString *)image highImage:(NSString *)highImage title:(NSString *)title target:(id)target action:(SEL)action {
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 0, 50, 20);
    [backButton setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [backButton setTitle:title forState:UIControlStateNormal];
    [backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [backButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    backButton.titleLabel.font = [SSSFont systemFontOfSize:18];
    [backButton sizeToFit];
    backButton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -10);
    return [[self alloc]initWithCustomView:backButton];
}

/**
 *  导航栏左边按钮
 *
 *  @param image     图片
 *  @param highImage 高亮图片
 *  @param title     显示文字
 *  @param color     文字颜色
 *  @param target    对象self
 *  @param action    方法
 *
 *  @return 按钮
 */
+ (instancetype)itemLeftTitleColorWithImage:(NSString *)image highImage:(NSString *)highImage title:(NSString *)title color:(UIColor *)color target:(id)target action:(SEL)action {
    
    UIButton *signOutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    signOutBtn.titleLabel.font = [SSSFont systemFontOfSize:18];
    [signOutBtn setTitleColor:color forState:UIControlStateNormal];
    [signOutBtn setTitle:title forState:UIControlStateNormal];
    [signOutBtn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [signOutBtn setImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
    [signOutBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [signOutBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
    [signOutBtn sizeToFit];
    signOutBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    return [[self alloc]initWithCustomView:signOutBtn];
}

/**
 *  导航栏右边按钮
 *
 *  @param image     图片
 *  @param highImage 高亮图片
 *  @param title     显示文字
 *  @param color     文字颜色
 *  @param target    对象self
 *  @param action    方法
 *
 *  @return 按钮
 */
+ (instancetype)itemRightTitleColorWithImage:(NSString *)image highImage:(NSString *)highImage title:(NSString *)title color:(UIColor *)color target:(id)target action:(SEL)action {
    
    UIButton *signOutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    signOutBtn.frame     = CGRectMake(0, 0, 90, 30);
//    signOutBtn.titleLabel.font = [SSSFont systemFontOfSize:18];
//    [signOutBtn setTitleColor:color forState:UIControlStateNormal];
//    [signOutBtn setTitle:title forState:UIControlStateNormal];
    [signOutBtn setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [signOutBtn setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateHighlighted];
    [signOutBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    CGRect rect = signOutBtn.frame;
    [signOutBtn setImageEdgeInsets:UIEdgeInsetsMake(0,rect.size.width/2,0,0)];
    [signOutBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -rect.size.width/2, 0, 0)];
    
    signOutBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -10);
    [signOutBtn sizeToFit];
    return [[self alloc]initWithCustomView:signOutBtn];
}


@end
